<template>
  <div class="top">
    <div id="main">
      <el-page-header @back="goBack" content="详情页面"></el-page-header>
      <div class="nybasetit">
        <h3>From Food Material to Food</h3>
        <span>从食材到美食</span>
        <div class="yezi"></div>
      </div>
      <div class="contain" v-for="list in top" :key="list.menuId">
        <div class="pic">
          <img :src="getPic(list.menuPic)" />
        </div>
        <ul class="uu">
          <li>
            <h2>{{list.menuName}}</h2>
          </li>
          <li>
            <span>益处：</span>
            {{list.goods}}
          </li>
          <li>
            <span>营养价值：</span>
            {{list.menuValue}}
          </li>
          <li>
            <span>做法：</span>
            {{list.menumake}}
          </li>'
        </ul>
      </div>
      <!-- 将点赞数传到子组件 -->
      <menuchat :meallikeNum="meallikeNum" :headPic="headPic" :userName="userName"></menuchat>
    </div>
  </div>
</template>
<script>
import Menuchat from "../components/Menuchat.vue";
export default {
  data() {
    return {
      top: [],
      meallikeNum: ""
    };
  },
  props:["headPic","userName"],
  //子组件点赞评论收藏
  components: {
    Menuchat
  },
  created() {
    //获取榜单详情
    // console.log(this.$route.params);
    var mealId = this.$route.params.mealId;
    this.$axios
      .get("http://localhost:3000/menu/detail/" + mealId)
      .then(res => {
        console.log("查询结果：", res.data.data);
        this.top = res.data.data;
      })
      .catch(err => {
        console.log("错误信息：", err);
      });
      //获取该榜单点赞数
    this.$axios
      .get("http://localhost:3000/menu/top")
      .then(res => {
        // console.log(res.data.data);
        for (let i = 0; i < res.data.data.length; i++) {
          if (res.data.data[i].mealId == mealId) {
            this.meallikeNum = res.data.data[i].meallikeNum;
          }
        }
      })
      .catch(err => {
        console.log("错误信息：", err);
      });
  },
  methods: {
    getPic(pic) {
      return require("../assets/images/" + pic);
    },
    goBack() {
      this.$router.go(-1)
    }
  }
};
</script>
<style lang="css" scoped>
.el-page-header{
  margin-top: 20px;
}
#main {
  width: 80%;
  margin: auto;
  min-width: 1200px;
}

#main .contain {
  float: left;
  /* width: 100%; */
  margin-top: 30px;
  cursor: pointer;
}

#main .contain .pic {
  float: left;
  width: 45%;
  height: 350px;
  margin: 30px 15px;
  overflow: hidden;
}

.nybasetit {
  text-align: center;
}

.nybasetit h3 {
  font-size: 42px;
  font-family: arial;
  color: #111;
  margin-top: 80px;
}

.nybasetit span {
  font-size: 16px;
  display: block;
}

.nybasetit img {
  margin: 30px 0;
}

#main .nybasetit .yezi {
  height: 40px;
  background: url(../assets/images/base1.png) no-repeat center;
  margin: 30px 0;
}

#main .contain .pic img {
  float: left;
  width: 100%;
  height: 350px;
  transition: 0.5s;
}

#main .contain:hover img {
  transform: scale(1.2);
}

#main .contain:hover h2 {
  color: #61b662;
}

#main h2 {
  float: left;
  width: 100%;
  text-align: center;
  font-size: 24px;
  height: 35px;
  line-height: 35px;
  overflow: hidden;
  color: #333;
  font-family: "微软雅黑";
}

#main ul {
  float: left;
  width: 50%;
  margin: 0 15px;
  /* background: linear-gradient(45deg, rgb(160, 190, 117), rgb(255, 255, 255)) fixed; */
}

#main ul li {
  float: left;
  width: 90%;
  margin-left: 5%;
  margin-top: 4%;
}

#main ul li span {
  color: #333;
  font-weight: bolder;
  font-size: 20px;
}
</style>